package view;

import controller.IClienteCtrl;
import java.text.ParseException;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.MaskFormatter;
import model.ICliente;
import model.Observer;

public class ClienteGUI extends javax.swing.JFrame implements Observer {    
    
    private MaskFormatter data,cpf,tel,cel,cep,uf;
    private ICliente model;
    private IClienteCtrl clienteCtrl;
    
    public ClienteGUI(ICliente model,IClienteCtrl clienteCtrl) {                
        this.clienteCtrl = clienteCtrl;       
        this.model = model;    
        this.model.registrarObserver(this);
    }     
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupSexo = new javax.swing.ButtonGroup();
        jToolBar2 = new javax.swing.JToolBar();
        jPanel1 = new javax.swing.JPanel();
        jtfdDataNasc = new javax.swing.JFormattedTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jtfdEmail = new javax.swing.JTextField();
        jtfdTelefone = new javax.swing.JFormattedTextField();
        jtfdCelular = new javax.swing.JFormattedTextField();
        jLabel4 = new javax.swing.JLabel();
        jtfdCodigo = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jtfdCpf = new javax.swing.JFormattedTextField();
        jLabel9 = new javax.swing.JLabel();
        jtfdNome = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jtfdRg = new javax.swing.JFormattedTextField();
        jLabel3 = new javax.swing.JLabel();
        mascRadioButton1 = new javax.swing.JRadioButton();
        femRadioButton2 = new javax.swing.JRadioButton();
        jLabel15 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jtfdEndereco = new javax.swing.JTextField();
        jtfdBairro = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jtfdCidade = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jtfdCep = new javax.swing.JFormattedTextField();
        jtfdUf = new javax.swing.JFormattedTextField();
        jLabel16 = new javax.swing.JLabel();
        jToolBar3 = new javax.swing.JToolBar();
        jPanel4 = new javax.swing.JPanel();
        jbtnNovo = new javax.swing.JButton();
        jbtnSalvar = new javax.swing.JButton();
        jbtnCancelar = new javax.swing.JButton();
        jbtnExcluir = new javax.swing.JButton();
        jbtnPrimeiro = new javax.swing.JButton();
        jbtnAnterior = new javax.swing.JButton();
        jbtnProximo = new javax.swing.JButton();
        jbtnUltimo = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jcbxPesquisa = new javax.swing.JComboBox();
        jtfdPesquisa = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtblPesquisa = new javax.swing.JTable();
        jbtnPesquisar = new javax.swing.JButton();
        jSeparator12 = new javax.swing.JSeparator();
        jSeparator13 = new javax.swing.JSeparator();
        jLabel10 = new javax.swing.JLabel();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jPanel6 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jDesktopPane2 = new javax.swing.JDesktopPane();
        jButton2 = new javax.swing.JButton();

        jToolBar2.setFloatable(false);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Controle de Leitor");
        setMinimumSize(new java.awt.Dimension(974, 489));
        setPreferredSize(new java.awt.Dimension(974, 489));
        setResizable(false);
        getContentPane().setLayout(null);

        jPanel1.setBackground(new java.awt.Color(235, 231, 231));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados Pessoais", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        jPanel1.setForeground(new java.awt.Color(0, 0, 255));

        jtfdDataNasc.setColumns(8);
        jtfdDataNasc.setText("__/__/____");
        jtfdDataNasc.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtfdDataNasc.setSelectionStart(22);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel5.setText("CPF:");

        jLabel6.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel6.setText("Código:");

        jtfdEmail.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtfdEmail.setSelectionStart(22);

        jtfdTelefone.setText("(##) ####-####");
        jtfdTelefone.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtfdTelefone.setSelectionStart(22);

        jtfdCelular.setText("(##) ####-####");
        jtfdCelular.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtfdCelular.setSelectionStart(22);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel4.setText("RG:");

        jtfdCodigo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtfdCodigo.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jtfdCodigo.setEnabled(false);
        jtfdCodigo.setSelectionStart(22);

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel7.setText("E-mail:");

        jtfdCpf.setText("###.###.###-##");
        jtfdCpf.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtfdCpf.setSelectionStart(22);

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel9.setText("Cel.:");

        jtfdNome.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtfdNome.setSelectionStart(22);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel8.setText("Tel.:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setText("Nome:");

        jtfdRg.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtfdRg.setSelectionStart(22);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setText("Nascimento:");

        buttonGroupSexo.add(mascRadioButton1);
        mascRadioButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        mascRadioButton1.setText("Mas");
        mascRadioButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        mascRadioButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));

        buttonGroupSexo.add(femRadioButton2);
        femRadioButton2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        femRadioButton2.setText("Fem");
        femRadioButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        femRadioButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel15.setText("Sexo:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addGap(0, 411, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jtfdEmail)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfdTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jtfdDataNasc, 0, 0, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(mascRadioButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(femRadioButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(1, 1, 1)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfdRg, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jtfdCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(jtfdCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jtfdCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfdNome)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(0, 0, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(5, 5, 5)
                        .addComponent(jtfdCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfdNome, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(9, 9, 9)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel4)
                                .addComponent(jLabel5)))
                        .addGap(5, 5, 5)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(femRadioButton2)
                                .addComponent(jtfdRg, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(mascRadioButton1)
                                .addComponent(jtfdCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jtfdDataNasc, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfdCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfdEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfdTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        getContentPane().add(jPanel1);
        jPanel1.setBounds(10, 254, 606, 179);

        jPanel2.setBackground(new java.awt.Color(235, 231, 231));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Endereço", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel13.setText("Logradouro:");
        jPanel2.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, -1, -1));

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel14.setText("Bairro:");
        jPanel2.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, -1, -1));

        jtfdEndereco.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtfdEndereco.setSelectionStart(22);
        jPanel2.add(jtfdEndereco, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, 310, 22));

        jtfdBairro.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtfdBairro.setSelectionStart(22);
        jPanel2.add(jtfdBairro, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, 200, 22));

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel17.setText("CEP:");
        jPanel2.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 70, 40, -1));

        jtfdCidade.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtfdCidade.setSelectionStart(22);
        jPanel2.add(jtfdCidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 140, 270, 22));

        jLabel18.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel18.setText("Cidade:");
        jPanel2.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 120, -1, -1));

        jLabel21.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel21.setText("UF:");
        jPanel2.add(jLabel21, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 120, -1, 10));

        jtfdCep.setText("######-###");
        jtfdCep.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtfdCep.setSelectionStart(22);
        jPanel2.add(jtfdCep, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 90, 100, 22));

        jtfdUf.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jtfdUf.setSelectionStart(22);
        jPanel2.add(jtfdUf, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 140, 30, -1));

        getContentPane().add(jPanel2);
        jPanel2.setBounds(622, 254, 333, 179);

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel16.setText("Controle de Clientes");
        getContentPane().add(jLabel16);
        jLabel16.setBounds(0, 0, 964, 37);

        jToolBar3.setFloatable(false);
        getContentPane().add(jToolBar3);
        jToolBar3.setBounds(0, 716, 964, 25);

        jPanel4.setBackground(new java.awt.Color(217, 228, 231));
        jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 0, 255)));
        jPanel4.setLayout(new java.awt.GridLayout(1, 0));

        jbtnNovo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/incl.png"))); // NOI18N
        jbtnNovo.setMnemonic('x');
        jbtnNovo.setText("Novo");
        jbtnNovo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jbtnNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnNovoActionPerformed(evt);
            }
        });
        jPanel4.add(jbtnNovo);

        jbtnSalvar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/atualizar25.png"))); // NOI18N
        jbtnSalvar.setMnemonic('t');
        jbtnSalvar.setText("Salvar");
        jbtnSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jbtnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSalvarActionPerformed(evt);
            }
        });
        jPanel4.add(jbtnSalvar);

        jbtnCancelar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/can.png"))); // NOI18N
        jbtnCancelar.setMnemonic('L');
        jbtnCancelar.setText("Cancelar");
        jbtnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jbtnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnCancelarActionPerformed(evt);
            }
        });
        jPanel4.add(jbtnCancelar);

        jbtnExcluir.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/excluir25.png"))); // NOI18N
        jbtnExcluir.setMnemonic('I');
        jbtnExcluir.setText("Excluir");
        jbtnExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jbtnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnExcluirActionPerformed(evt);
            }
        });
        jPanel4.add(jbtnExcluir);

        jbtnPrimeiro.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnPrimeiro.setText("<<");
        jbtnPrimeiro.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jbtnPrimeiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnPrimeiroActionPerformed(evt);
            }
        });
        jPanel4.add(jbtnPrimeiro);

        jbtnAnterior.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnAnterior.setText("<");
        jbtnAnterior.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jbtnAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAnteriorActionPerformed(evt);
            }
        });
        jPanel4.add(jbtnAnterior);

        jbtnProximo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnProximo.setText(">");
        jbtnProximo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jbtnProximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnProximoActionPerformed(evt);
            }
        });
        jPanel4.add(jbtnProximo);

        jbtnUltimo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnUltimo.setText(">>");
        jbtnUltimo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jbtnUltimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnUltimoActionPerformed(evt);
            }
        });
        jPanel4.add(jbtnUltimo);

        getContentPane().add(jPanel4);
        jPanel4.setBounds(10, 444, 945, 35);

        jPanel3.setBackground(new java.awt.Color(217, 228, 231));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, new java.awt.Color(102, 0, 255), new java.awt.Color(102, 0, 255)), "Clientes", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), java.awt.Color.black)); // NOI18N
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jcbxPesquisa.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jcbxPesquisa.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel3.add(jcbxPesquisa, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, 110, 20));

        jtfdPesquisa.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtfdPesquisa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jtfdPesquisaKeyReleased(evt);
            }
        });
        jPanel3.add(jtfdPesquisa, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 40, 640, 20));

        jtblPesquisa.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jtblPesquisa.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Título 1", "Título 2", "Título 3", "Título 4"
            }
        ));
        jtblPesquisa.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtblPesquisaMouseClicked(evt);
            }
        });
        jtblPesquisa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jtblPesquisaKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jtblPesquisa);

        jPanel3.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 70, 910, 110));

        jbtnPesquisar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jbtnPesquisar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/pesquisar.png"))); // NOI18N
        jbtnPesquisar.setMnemonic('C');
        jbtnPesquisar.setText("Buscar");
        jbtnPesquisar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jbtnPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnPesquisarActionPerformed(evt);
            }
        });
        jPanel3.add(jbtnPesquisar, new org.netbeans.lib.awtextra.AbsoluteConstraints(810, 30, 120, 30));

        jSeparator12.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel3.add(jSeparator12, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 40, -1, 20));

        jSeparator13.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel3.add(jSeparator13, new org.netbeans.lib.awtextra.AbsoluteConstraints(800, 40, 10, 20));

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel10.setText("Pesquisar Por:");
        jPanel3.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, 130, -1));

        getContentPane().add(jPanel3);
        jPanel3.setBounds(10, 43, 945, 200);

        jButton1.setText("jButton1");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(127, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(44, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(33, 33, 33))
        );

        jPanel6.setBounds(150, 0, 210, 100);
        jDesktopPane1.add(jPanel6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        getContentPane().add(jDesktopPane1);
        jDesktopPane1.setBounds(60, 600, 850, 120);

        jButton2.setText("jButton2");
        jButton2.setBounds(470, 20, 73, 23);
        jDesktopPane2.add(jButton2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        getContentPane().add(jDesktopPane2);
        jDesktopPane2.setBounds(40, 540, 780, 110);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-990)/2, (screenSize.height-780)/2, 990, 780);
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCancelarActionPerformed
        limpaTela();        
    }//GEN-LAST:event_jbtnCancelarActionPerformed

    private void jbtnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnExcluirActionPerformed
        String[] botoes = {"Sim", "Não"};
        int n = JOptionPane.showOptionDialog(this, "Tem certeza que deseja excluir o item?",
                "Apagar ?", JOptionPane.DEFAULT_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, botoes, botoes[0]);
        if (n == 0) {
            clienteCtrl.excluir(Integer.parseInt(jtfdCodigo.getText()));
            limpaTela();
        } else {
            JOptionPane.showMessageDialog(null, "Selecione a Unidade");
        }
    }//GEN-LAST:event_jbtnExcluirActionPerformed

    private void jbtnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSalvarActionPerformed
        ArrayList<String> registro = new ArrayList<String>();
        registro.add(jtfdCodigo.getText());
        registro.add(jtfdNome.getText());
        registro.add(jtfdBairro.getText());
        registro.add(jtfdCep.getText());
        registro.add(jtfdCidade.getText());
        registro.add(jtfdCpf.getText());
        registro.add(jtfdDataNasc.getText());
        registro.add(jtfdEmail.getText());
        registro.add(jtfdEndereco.getText());
        registro.add(jtfdPesquisa.getText());
        registro.add(jtfdRg.getText());
        registro.add(jtfdTelefone.getText());
        registro.add(jtfdUf.getText());        

        int codigoAtual = Integer.parseInt(jtfdCodigo.getText());

        if (codigoAtual > 0) {
//            clienteCtrl.atualizar(registro);
        } else {
//            jtfdCodigo.setText(String.valueOf(clienteCtrl.inserir(registro)));
        }
        habilitaDesabilitaBotoes(true);
        atualizarDados();
    }//GEN-LAST:event_jbtnSalvarActionPerformed

    private void jbtnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNovoActionPerformed
        limpaTela();
        jtfdNome.requestFocus();
        jtfdCodigo.setText("0");          
        jDesktopPane1.moveToBack(this);
        habilitaDesabilitaBotoes(false);
    }//GEN-LAST:event_jbtnNovoActionPerformed

    private void jbtnPrimeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnPrimeiroActionPerformed
        jtblPesquisa.setRowSelectionInterval(0, 0);
        jtblPesquisaMouseClicked(null);
    }//GEN-LAST:event_jbtnPrimeiroActionPerformed

    private void jbtnAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAnteriorActionPerformed
        int linhaSelecionada = jtblPesquisa.getSelectedRow();
        if (linhaSelecionada > 0) {
            jtblPesquisa.setRowSelectionInterval(linhaSelecionada - 1, linhaSelecionada - 1);
            jtblPesquisaMouseClicked(null);
        }
    }//GEN-LAST:event_jbtnAnteriorActionPerformed

    private void jbtnProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnProximoActionPerformed
        int linhaSelecionada = jtblPesquisa.getSelectedRow();
        int totalLinhas = jtblPesquisa.getRowCount();

        if (linhaSelecionada < (totalLinhas - 1)) {
            jtblPesquisa.setRowSelectionInterval(linhaSelecionada + 1, linhaSelecionada + 1);
            jtblPesquisaMouseClicked(null);
        }
    }//GEN-LAST:event_jbtnProximoActionPerformed

    private void jbtnUltimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnUltimoActionPerformed
        int totalLinhas = jtblPesquisa.getRowCount();
        jtblPesquisa.setRowSelectionInterval(totalLinhas - 1, totalLinhas - 1);
        jtblPesquisaMouseClicked(null);
    }//GEN-LAST:event_jbtnUltimoActionPerformed

    private void jtfdPesquisaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfdPesquisaKeyReleased
        if (evt.getKeyCode() == evt.VK_ENTER) {
            jbtnPesquisarActionPerformed(null);
        }
    }//GEN-LAST:event_jtfdPesquisaKeyReleased

    private void jtblPesquisaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtblPesquisaMouseClicked
        jtfdCodigo.setText((String) jtblPesquisa.getValueAt(jtblPesquisa.getSelectedRow(), 0));
        jtfdNome.setText((String) jtblPesquisa.getValueAt(jtblPesquisa.getSelectedRow(), 1));
        jtfdBairro.setText((String) jtblPesquisa.getValueAt(jtblPesquisa.getSelectedRow(), 2));
        jtfdCep.setText((String) jtblPesquisa.getValueAt(jtblPesquisa.getSelectedRow(), 3));
        jtfdCidade.setText((String) jtblPesquisa.getValueAt(jtblPesquisa.getSelectedRow(), 4));
        jtfdCpf.setText((String) jtblPesquisa.getValueAt(jtblPesquisa.getSelectedRow(), 5));
        jtfdDataNasc.setText((String) jtblPesquisa.getValueAt(jtblPesquisa.getSelectedRow(), 6));
        jtfdEmail.setText((String) jtblPesquisa.getValueAt(jtblPesquisa.getSelectedRow(), 7));
        jtfdEndereco.setText((String) jtblPesquisa.getValueAt(jtblPesquisa.getSelectedRow(), 8));        
        jtfdRg.setText((String) jtblPesquisa.getValueAt(jtblPesquisa.getSelectedRow(), 9));
        jtfdTelefone.setText((String) jtblPesquisa.getValueAt(jtblPesquisa.getSelectedRow(), 10));
        jtfdCelular.setText((String) jtblPesquisa.getValueAt(jtblPesquisa.getSelectedRow(), 11));        
        jtfdUf.setText((String) jtblPesquisa.getValueAt(jtblPesquisa.getSelectedRow(), 12));        
    }//GEN-LAST:event_jtblPesquisaMouseClicked

    private void jtblPesquisaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtblPesquisaKeyReleased
        jtblPesquisaMouseClicked(null);
    }//GEN-LAST:event_jtblPesquisaKeyReleased

    private void jbtnPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnPesquisarActionPerformed
        if ((jcbxPesquisa.getSelectedItem() == "Código") && (jtfdPesquisa.getText().equals(""))) {
            JOptionPane.showMessageDialog(null, "Informe o Código!");
            jtfdCodigo.requestFocus();
        } else {
            DefaultTableModel model = new DefaultTableModel(new String[]{"Código", "Descrição"}, 0);
            String iPesquisa = "";
            int iOpcao = 0;
            if (jcbxPesquisa.getSelectedItem() == "Código") {
//                iOpcao = ClienteDAO2.CL_CODIGO;
            } else {
//                iOpcao = ClienteDAO2.CL_NOME;
            }
            iPesquisa = jtfdPesquisa.getText();            
//            jtblPesquisa.setModel(clienteCtrl.pesquisar(iOpcao, iPesquisa, model));
        }
    }//GEN-LAST:event_jbtnPesquisarActionPerformed
                                       
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupSexo;
    private javax.swing.JRadioButton femRadioButton2;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JDesktopPane jDesktopPane2;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator12;
    private javax.swing.JSeparator jSeparator13;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JToolBar jToolBar3;
    private javax.swing.JButton jbtnAnterior;
    private javax.swing.JButton jbtnCancelar;
    private javax.swing.JButton jbtnExcluir;
    private javax.swing.JButton jbtnNovo;
    private javax.swing.JButton jbtnPesquisar;
    private javax.swing.JButton jbtnPrimeiro;
    private javax.swing.JButton jbtnProximo;
    private javax.swing.JButton jbtnSalvar;
    private javax.swing.JButton jbtnUltimo;
    private javax.swing.JComboBox jcbxPesquisa;
    private javax.swing.JTable jtblPesquisa;
    private javax.swing.JTextField jtfdBairro;
    private javax.swing.JFormattedTextField jtfdCelular;
    private javax.swing.JFormattedTextField jtfdCep;
    private javax.swing.JTextField jtfdCidade;
    private javax.swing.JTextField jtfdCodigo;
    private javax.swing.JFormattedTextField jtfdCpf;
    private javax.swing.JFormattedTextField jtfdDataNasc;
    private javax.swing.JTextField jtfdEmail;
    private javax.swing.JTextField jtfdEndereco;
    private javax.swing.JTextField jtfdNome;
    private javax.swing.JTextField jtfdPesquisa;
    private javax.swing.JFormattedTextField jtfdRg;
    private javax.swing.JFormattedTextField jtfdTelefone;
    private javax.swing.JFormattedTextField jtfdUf;
    private javax.swing.JRadioButton mascRadioButton1;
    // End of variables declaration//GEN-END:variables
 
    private void limpaTela(){
        jtfdCodigo.setText("0");
        jtfdNome.setText(null);
        jtfdTelefone.setText(null);
        jtfdEmail.setText(null);
        jtfdCelular.setText(null);
//        jtfdFax.setText(null);
//        jtfdCnpj.setText(null);
//        jtfdContato.setText(null);
        jtfdRg.setText(null);
//        jtfdOrgao.setText(null);
        jtfdCpf.setText(null);
        jtfdEndereco.setText(null);
        jtfdBairro.setText(null);
        jtfdCidade.setText(null);
        jtfdUf.setText(null);
        jtfdCep.setText(null);
//        jtfdDataCadastro.setText(null); 
//        jtaObs.setText(null);       
        habilitaDesabilitaBotoes(true);        
    }
    
    public void inserirDadosTable(ArrayList list){ 
        DefaultTableModel modelo = new DefaultTableModel(new String[]{"Código","Nome","Telefone","E-mail","Celular",
           "Fax","CNPJ","Contato","RG","Orgão RG","CPF","Rua","Bairro","Cidade","UF","CEP","Data Cadastro","Observação","Auditoria"}, 0);             
        jtblPesquisa.setModel(modelo);               
        for (int i = 0; i < list.size(); i++) {
            modelo.addRow((String[])list.get(i));            
        }
    }  
    
    private void atualizarDadosTable(){ 
        ArrayList list;
        list = clienteCtrl.getAll();
        inserirDadosTable(list);
    }
    
    private void atualizarDadosTable(ArrayList list){ 
        inserirDadosTable(list);    
    }
    
    private void inserirDadosCombo(){        
        jcbxPesquisa.setModel(new DefaultComboBoxModel(new String[]{"Código"}));            
        jcbxPesquisa.addItem("Nome");            
        jcbxPesquisa.addItem("Cidade");            
        jcbxPesquisa.addItem("CNPJ");            
        jcbxPesquisa.addItem("CPF");
        jcbxPesquisa.addItem("Data Cadastro");                  
    }
    
    private void habilitaDesabilitaBotoes(boolean Habilita){        
        jbtnPrimeiro.setEnabled(Habilita);
        jbtnAnterior.setEnabled(Habilita);
        jbtnProximo.setEnabled(Habilita);
        jbtnUltimo.setEnabled(Habilita);
        jbtnNovo.setEnabled(Habilita);
        jbtnSalvar.setEnabled(!Habilita);
        jbtnCancelar.setEnabled(!Habilita);
        jbtnExcluir.setEnabled(Habilita);
        jbtnPesquisar.setEnabled(Habilita);        
    }  
    
    private void icoTitle(){
        java.net.URL imgURL = UnidadeGUI.class.getResource("/icones/ico_barra.png");
        setIconImage(new ImageIcon(imgURL).getImage());
    }
    
    private void atualizarDados(){
        inserirDadosCombo();
        atualizarDadosTable();        
    }
    
    public void criarTela(){
        initComponents();
        setVisible(true);
        habilitaDesabilitaBotoes(true);        
        atualizarDados();
        icoTitle();
    }
    
     private void inserirFormato(){
                
        try {
            uf = new MaskFormatter("UU");
            cep = new MaskFormatter("#####-###");
            data = new MaskFormatter("##/##/####");
            cpf = new MaskFormatter("###.###.###-##");
            tel = new MaskFormatter("(##) ####-####");
            cel = new MaskFormatter("(##) ####-####");            
        } catch (ParseException ex) {
            JOptionPane.showMessageDialog(null,ex.getMessage());
        }
        cep.setPlaceholderCharacter('_');
        cep.install(jtfdCep);
        cpf.setPlaceholderCharacter('_');
        cpf.install(jtfdCpf);
        tel.setPlaceholderCharacter('_');
        tel.install(jtfdTelefone);
        cel.setPlaceholderCharacter('_');
        cel.install(jtfdCelular);
        data.setPlaceholderCharacter('_');
        data.install(jtfdDataNasc);
        uf.install(jtfdUf);        
    }    

    @Override
    public void update() {
        atualizarDados();
    } 
    
}